using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AxMicrosoft.Office.Interop.Owc11;
using Microsoft.AnalysisServices.AdomdClient;
using RetailAnalytic.Core;

namespace RetailAnalytic.Tools.Writeback
{
    public partial class frmWriteback : Form
    {
        string coordinate;
        public string weight = String.Empty;
        public WBSupport coordinateStruct;
        public string newValue;
        string MDXQueries = String.Empty;
        public AdomdConnection conn;
        public AdomdConnection conn1;

        public string newMeasure = String.Empty;
        public int mode = 0;
        public int lag = 0;

        public frmWriteback(AdomdConnection connect, WBSupport coord)
        {
            string where = coord.getWhereDim();
            if (where != String.Empty)
            {
                where = ", " + where.Substring(7, where.Length - 7);
            }
            coordinate = coord.getCoordValue() + where;
            InitializeComponent();
            ultraLabel1.Text = coordinate;
            coordinateStruct = coord;
            conn = connect;
            //conn1 = connect1;
        }

        private void frmWriteback_Load(object sender, EventArgs e)
        {
            ultraFormattedTextEditor1.Text = ultraOptionSet1.Items[ultraOptionSet1.ValueList.SelectedIndex].Tag.ToString();
        }

        private void ultraButton1_Click(object sender, EventArgs e)
        {
              if (ultraMaskedEdit1.Text == String.Empty)
              {
                  Dialog.Show(Dialog_type.Question, SR.StringLibrary.GetStrMSG(RetailAnalytic.SR.StringLibrary.KeyEnum.Ask_INPUT_VALUE,
                      Environment.StackTrace, ""));
              }
              else
              {
                  string option = ultraOptionSet1.Items[ultraOptionSet1.ValueList.SelectedIndex].DataValue.ToString();
                  if (WBService.Write(coordinateStruct, newMeasure, ultraMaskedEdit1.Text, option, conn, mode, lag))
                  {
                      Close();
                  }
              }
        }

        private void ultraOptionSet1_ValueChanged(object sender, EventArgs e)
        {
            ultraFormattedTextEditor1.Text = ultraOptionSet1.Items[ultraOptionSet1.ValueList.SelectedIndex].Tag.ToString();
            if (ultraOptionSet1.ValueList.SelectedIndex > 1) 
            { 
                ultraButton3.Enabled = true;
            } 
            else 
            { 
                ultraButton3.Enabled = false;
            };
            if ((ultraOptionSet1.ValueList.SelectedIndex==1) ||(ultraOptionSet1.ValueList.SelectedIndex == 3))
            {
                ultraLabel3.Visible = true;
            }
            else
            {
                ultraLabel3.Visible = false;
            }
        }

        private void ultraButton2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ultraButton3_Click(object sender, EventArgs e)
        {
           frmSettings frmSet = new frmSettings(this);
           frmSet.ShowDialog();
        }

    }
}